
<!DOCTYPE html>
<html lang="en">
<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>UMS | Login</title>
    <link rel="icon" href="<?php echo base_url('assets'); ?>/favicon.ico" type="image/x-icon" />
    <link href="<?php echo base_url('assets/css/bootstrap.min.css'); ?>" rel="stylesheet">
    <link href="<?php echo base_url('assets/font-awesome/css/font-awesome.css'); ?>" rel="stylesheet">
    <link href="<?php echo base_url('assets/css/animate.css'); ?>" rel="stylesheet">
    <link href="<?php echo base_url('assets/css/style.css'); ?>" rel="stylesheet">

    <!-- Mainly scripts -->
    <script src="<?php echo base_url('assets/js/jquery-2.1.1.js'); ?>"></script>
    <script src="<?php echo base_url('assets/js/bootstrap.min.js'); ?>"></script>
    <script src="<?php echo base_url('assets/js/plugins/validate/jquery.validate.min.js'); ?>"></script>
    <script src="<?php echo base_url(); ?>assets/js/plugins/metisMenu/jquery.metisMenu.js"></script>
    <script src="<?php echo base_url(); ?>assets/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>

    <!-- Custom and plugin javascript -->
    <script src="<?php echo base_url(); ?>assets/js/inspinia.js"></script>
    <script src="<?php echo base_url(); ?>assets/js/plugins/pace/pace.min.js"></script>
    <script src="<?php echo base_url('assets/js/login.js'); ?>"></script>

</head>
<body class="gray-bg">

    <div class="middle-box text-center loginscreen">
        <div class="login">
            <div>
                 <img alt="image" class="img m-b-md" src="<?php echo base_url('assets/img/logo.png'); ?>" style="width:150; height:150px;" />
            </div>
            <h3>Welcome to UMS</h3>
            <form class="m-t animated fadeInDown" role="form" id="login_form">
                <div class="form-group">
                    <input style="text-align: center;" type="text" name="user_name" class="form-control" placeholder="Email/Username" required="">
                </div>
                <div class="form-group">
                    <input style="text-align: center;" type="password" name="password" class="form-control" placeholder="Password" required="">
                </div>
                <button type="button" class="btn btn-success block full-width m-b" id="login_btn">Login</button>
                <button type="button" class="btn btn-link full-width m-b" id="signup_btn">Lost Passord?</button>
            </form>
            <form class="m-t animated fadeInRight" role="form" id="signup_form" style="display: none;">
                <button type="button" class="btn btn-link pull-left" id="back_btn"><i class="fa fa-arrow-left fa-fw"></i>&nbsp;Back</button></br>
                <div class="form-group">
                    <input data-toggle="tooltip" data-placement="left" title="Tooltip on left"  style="text-align: center;" type="text" name="email" class="form-control" placeholder="Email Address">
                </div>
                <button type="button" class="btn btn-success block full-width m-b" id="register_btn">Reset Password</button>
            </form>
            <div style="display: none;" id='login-msg' class="alert alert-danger alert-dismissable">
                <span id="login-msg-2"></span>
            </div>
             <div style="display: none;" id='login-msg-suc' class="alert alert-success alert-dismissable">
                <span id="login-msg-3"></span>
            </div>

            <p class="m-t"> <small>BizlerTech | Your IT Business Enabler.  &copy; 2015</small> </p>
        </div>
    </div>
    <script>
        $(document).ready(function() {
            $('#register_btn').click(function(){
                //console.log(get_acctnum());
                if($('#signup_form').valid() == true){
                    $.ajax({
                            url: '<?php echo base_url(); ?>sample/forget_pwd',
                            method:'post',
                            data: $('#signup_form').serialize(),
                            dataType:'json',
                            success: function (data) {
                                if(data.error == 1){
                                    //location.assign(assign);
                                    var msg = data.msg;;
                                        $('#login-msg').show();
                                        $('#login-msg-2').html('<b>'+msg+'</b>');
                                    console.log('has error');
                                }else if(data.msg == 'success'){
                                    console.log('no error mail');
                                    $('#login_form').show();
                                    $('#signup_form').hide();
                                    $('#login-msg-suc').show();
                                    $('#login-msg-3').html('<b>Your New Password has been deliverd to your e-mail ('+$('input[name=email]').val()+').</b>');
                                    $('#signup_form')[0].reset();
                                    //$('#login-msg').show();
                                    //$('#login-msg-2').html(data.msg);
                                }else{
                                    console.log('error mail');
                                }
                            },
                            complete: function() {
                                $('#register_btn').removeAttr('disabled');
                                $('#register_btn').text('Reset Password');
                            },
                            beforeSend: function(){
                                $('#login-msg-suc').hide();
                                $('#login-msg').hide();
                                $('#register_btn').text('Reseting password. . .');
                                $('#register_btn').attr('disabled',true);
                            },
                            error: function(response, status, xhr) {
                              if (status == "error") {
                                    var msg = "Sorry but there was an error: ";
                                    $('#login-msg').show();
                                    $('#login-msg-2').html('<b>'+xhr+'</b>');
                                  }
                              }
                        });
                }
            });

           // var validator = $("#signup_form").validate();
            var validator = $('#signup_form').validate({
                    rules:{
                      email: {
                          required: true,
                          email: true,
                           remote: {
                                url: "sample/validate_email",
                                type: "post",
                                complete: function(data){
                                    if(data.responseJSON == "taken"){
                                        $('label').addClass("success")
                                    }
                                    console.log(data.responseJSON);
                                 }
                            }
                      }
                    },
                    messages: {
                        email: {
                          required: "We need your email address to contact you",
                          email: "Your email address must be in the format of name@domain.com",
                          remote: "Email Address Already Taken!"
                        }
                      }
                    });
            //$(document).on('keyup',$('input[name=account_num]'),function(event) {
            function get_acctnum() {
                sessionStorage.validate = 0;
                var errors;
                $.ajax({
                    url: 'sample/validate_acctnum',
                    method: 'POST',
                    async: false,
                    dataType: 'json',
                    data: { 'account_num' : $('input[name=account_num]').val() },
                    success: function(data){
                        console.log(data);
                        //errors = { account_num: "This Account Number is already in use." };
                        if(data === "taken"){
                            console.log(data+ 'test');
                            validator.showErrors({
                              account_num : "This Account Number is already in use."
                            });
                            errors = {  };
                            sessionStorage.validate = 0;
                            return false;
                        }else if(data === "not_found"){
                            console.log(data + 'test');
                            validator.showErrors({
                              account_num : "Not Recognize."
                            });
                            sessionStorage.validate = 0;
                            return false;
                        }else if(data === "available"){
                            console.log(data + 'test');
                            validator.showSuccess({
                              account_num : ""
                            });
                            sessionStorage.validate = 1;
                            return true;
                        }
                        console.log(sessionStorage.validate);
                        //validator.showErrors(errors);
                    }
                });
                //});
            }
        });
    </script>
</body>

</html>
